package com.geekband.Test01.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

public abstract class BaseGridAdapter<Data> extends BaseListAdapter<Data> {

    private View mFirstView;

    public BaseGridAdapter(Context context) {
        super(context);
    }

    public BaseGridAdapter(Context context, List<Data> list) {
        super(context, list);
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = onNewItemView(LayoutInflater.from(getContext()), parent);
        }

        if (position != 0) {
            if (position == 1) {
                //load the first view
                if (mFirstView != null) {
                    onBindItemView(mFirstView, getItem(0), 0, parent);
                }
            }
        } else {
            mFirstView = convertView;
            if (getCount() <= 1) {
                onBindItemView(mFirstView, getItem(0), 0, parent);
            }
            return mFirstView;
        }

        onBindItemView(convertView, getItem(position), position, parent);
        return convertView;
    }
}
